package com.neo.base.C04_keyVlueOperator.C04_02_pairTest

import org.apache.spark.{SparkConf, SparkContext}

object TransformOper {

  def splitTest(str: String): (String,String) ={
    val a = str.split(",")
    (a(0) , a(1))
  }

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[8]").setAppName("TransformOPer")
    val sc  = new SparkContext(conf)

    val lines = sc.parallelize(List("1,2","1,4","5,6"))

    val pair1 = lines.map(splitTest)

    println("*\n*\n*\n*\n*\npair1\n")
    pair1.take(10).foreach(println)

    val combines = pair1.reduceByKey((x,y) => x  + y)
    println("*\n*\n*\n*\n*\ncombines\n")
    combines.take(10).foreach(println)

    println("*\n*\n*\n*\n*\ngroupByKey()\n")
    val groupbykeys = pair1.groupByKey()
    groupbykeys.take(10).foreach(println)
    println("*\n*\n*\n*\n*\nmapValues\n")
    val mapvalues = pair1.mapValues(x => x + 1)
    mapvalues.take(10).foreach(println)
  }
}
